{% extends 'home.html' %}

{% block title %}
    <title>LDAP账号管理</title>
{% endblock %}

{% block custom_css %}

    <link href="/static/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="/static/switch/bootstrap-switch.min.css" rel="stylesheet">
    <link href="/static/css/jquery.resizableColumns.css" rel="stylesheet">
    {#    <link href="/static/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">#}
    <link href="/static/css/dataTables.bootstrap.css" rel="stylesheet">
    <link href="/static/css/style.min862f.css?v=4.1.0" rel="stylesheet">


    <!--template css-->
{% endblock %}

{% block content %}
    <div class="page-header">
        <div class="row">
            <div class="col-sm-6">
                <h4>LDAP管理</h4>
            </div>
        </div>
    </div>
    <div class="wrapper">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div style="text-align: left">
                            <a class=" btn btn-info" onclick="ale1111()"> LDAP信息录入</a>
                        </div>
                        <table class="table table-striped table-bordered table-hover dataTables-example">
                            <thead>
                            <tr>
                                <th style="display: none">id</th>
                                <th>账号</th>
                                <th>应用</th>
                                <th>申请人</th>
                                <th>申请部门</th>
                                <th>部门经理</th>
                                <th>账号权限</th>
                                <th>申请时间</th>
                                <th>到期时间</th>
                                <th>链接服务器</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for i in mess %}
                                <tr class="gradeU">
                                    <td style="display: none">{{ i.id }}</td>
                                    <td>{{ i.account }}</td>
                                    <td>{{ i.apps }}</td>
                                    <td>{{ i.applicant }}</td>
                                    <td>{{ i.application_division }}</td>
                                    <td>{{ i.manager }}</td>
                                    <td>{{ i.permission }}</td>
                                    {#                                    <td>{{ i.Application_Date |date:"Y-m-d"}}</td>#}
                                    {#                                    <td>{{ i.end |date:"Y-m-d H:i:s"}}</td>#}
                                    <td>{{ i.Application_Date }}</td>
                                    <td>{{ i.end }}</td>
                                    <td>{{ i.link_server }}</td>
                                    <td>
                                        <button type="button" class="btn btn-primary" onclick="ale('{{ i.id }}')"><span class="bold">操作</span></button>
                                        <button class="btn btn-warning " onclick="cancel('{{ i.id }}')" type="button"><i class="fa fa-warning"></i><span class="bold">删除</span></button>
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="myInfo" tabindex="-1" role="dialog" aria-labelledby="loginModal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h3 id="myladp">LDAP信息录入</h3>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" class="fa fa-times-circle"></span></button>
                </div>
                <div class="modal-body">
                    <div class="modal-form">
                        <form class=" animated bounceInRight form-horizontal" id="demoform" method="post" action="/insertldap/">
                            <div class="modal-body">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">账号：</label>
                                    <div class="col-sm-8">
                                        <input type="text" id="inputaccount" name="account" class="form-control">
                                        <input type="text" style="display: none" id="inpuid" name="id" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">应用：</label>
                                    <div class="col-sm-8">
                                        <input type="text" id="inputapps" name="apps" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">申请人：</label>
                                    <div class="col-sm-8">
                                        <input type="text" id="inputapplicant" name="applicant" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">申请部门：</label>
                                    <div class="col-sm-8">
                                        <input type="text" id="inputapplication_division" name="application_division" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">部门经理：</label>
                                    <div class="col-sm-8">
                                        <input type="text" id="inputmanager" name="manager" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">账号权限：</label>
                                    <div class="col-sm-8">
                                        <select class="form-control m-b" name="permission" id="inputpermission">
                                            <option value="普通账号">普通账号</option>
                                            <option value="管理账号">管理账号</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">申请时间：</label>
                                    <div class="col-sm-8">
                                        <input type="date" id="inputApplication_Date" name="Application_Date" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">到期时间：</label>
                                    <div class="col-sm-8">
                                        <input type="date" id="inputend" placeholder="选择时间" name="end" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">链接服务器：</label>
                                    <div class="col-sm-8">
                                        <input type="text" id="inputlink_server" name="link_server" class="form-control">
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                                <input class="btn btn-primary" id="sub" value="保存" type="submit">
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block custom_js %}

    <script src="/static/js/store.js"></script>
    <script src="/static/js/jquery.resizableColumns.min.js"></script>
    <script src="/static/js/jquery.dataTables.js"></script>
    <script src="/static/js/dataTables.bootstrap.js"></script>
    <script src="/static/js/jquery.form.js"></script>

    <script>
        $(function () {
            var options = {
                dataType: "json",
                async: true,
                success: function (data) {
                    if (data) {
                        swal({
                                    title: "",
                                    text: data,
                                    type: "success",
                                    showConfirmButton: "true",
                                    confirmButtonText: "好的",
                                    animation: "slide-from-top"
                                },
                                function () {
                                    window.location.reload();
                                })
                    }

                },
                error: function (e) {
                    swal("出错了，联系IT处理");
                }
            };
            $("#demoform").ajaxForm(options);
        });
    </script>
    <script>
        function ale(ids) {
            document.getElementById('inpuid').value = ids;
            $.ajax({
                url:{% url "getldapdbvaule" %},
                type: 'POST',
                dataType: 'json',
                data: {'ID': ids},
                success: function (data) {
                    if (data['isSuccess']) {
                        document.getElementById('inputaccount').value = fixXss(data['message']['account']);
                        document.getElementById('inputapps').value = fixXss(data['message']['apps']);
                        document.getElementById('inputapplicant').value = fixXss(data['message']['applicant']);
                        document.getElementById('inputapplication_division').value = fixXss(data['message']['application_division']);
                        document.getElementById('inputmanager').value = fixXss(data['message']['manager']);
                        $("#inputpermission").find("option[value=" + fixXss(data['message']['permission']) + "]").attr("selected", true);
                        document.getElementById('inputApplication_Date').value = fixXss(data['message']['Application_Date']);
                        document.getElementById('inputend').value = fixXss(data['message']['end']);
                        document.getElementById('inputlink_server').value = fixXss(data['message']['link_server']);
                        $('#myInfo').modal({
                            keyboard: true,
                        });
                    } else {
                        swal(data['message']);
                    }

                }
            })
        }
        function ale1111() {
            document.getElementById('inpuid').value = '';
            document.getElementById('inputaccount').value = '';
            document.getElementById('inputapps').value = '';
            document.getElementById('inputapplicant').value = '';
            document.getElementById('inputapplication_division').value = '';
            document.getElementById('inputmanager').value = '';
            document.getElementById('inputpermission').value = '';
            document.getElementById('inputApplication_Date').value = '';
            document.getElementById('inputend').value = '';
            document.getElementById('inputlink_server').value = '';
            $('#myInfo').modal({
                keyboard: true,
            });
        }
        $(document).ready(function () {
            $(".dataTables-example").dataTable();
            var oTable = $("#editable").dataTable();
            oTable.$("td").editable("http://www.zi-han.net/theme/example_ajax.php", {
                "callback": function (sValue, y) {
                    var aPos = oTable.fnGetPosition(this);
                    oTable.fnUpdate(sValue, aPos[0], aPos[1])
                }, "submitdata": function (value, settings) {
                    return {"row_id": this.parentNode.getAttribute("id"), "column": oTable.fnGetPosition(this)[2]}
                }, "width": "90%", "height": "100%"
            })
        });
        function fnClickAddRow() {
            $("#editable").dataTable().fnAddData(["Custom row", "New row", "New row", "New row", "New row"])
        }
        ;
        function cancel(ID) {
            $.ajax({
                url: "/deleteldap/",
                type: 'POST',
                dataType: 'json',
                data: {'ID': ID},
                success: function (data) {
                    if (data) {
                        swal({
                                    title: "",
                                    text: data,
                                    type: "success",
                                    showConfirmButton: "true",
                                    confirmButtonText: "好的",
                                    animation: "slide-from-top"
                                },
                                function () {
                                    window.location.reload();
                                });
                    } else {
                        swal("出错了，联系IT处理");
                    }
                }
            });
        }
    </script>
{% endblock %}